******** IDENTITY ********
gen _values=.
replace _values=0 if qd8==1
replace _values=.25 if qd8==2
replace _values=.5 if qd8==5
replace _values=.75 if qd8==3
replace _values=1 if qd8==4

gen _citizen=.
replace _citizen=0 if qd3==4
replace _citizen=.25 if qd3==3
replace _citizen=.5 if qd3==5 | qd3==6 | qd3==7
replace _citizen=.75 if qd3==2
replace _citizen=1 if qd3==1

gen D_Identity_std=(_citizen-.7808998)/.2167623
gen D_Identity_std_w=(_citizen-.7576051)/.234513
******** PERFORMANCE ********
gen _democracy=.
replace _democracy=0 if qa16b==1
replace _democracy=0.25 if qa16b==2
replace _democracy=0.5 if qa16b==5
replace _democracy=0.75 if qa16b==3
replace _democracy=1 if qa16b==4

gen _trust_1=0
replace _trust_1=0.5 if qa13_1==3
replace _trust_1=1 if qa13_1==2
gen _trust_2=0
replace _trust_2=0.5 if qa13_2==3
replace _trust_2=1 if qa13_2==2
gen _trust_3=0
replace _trust_3=0.5 if qa13_3==3
replace _trust_3=1 if qa13_3==2
gen _trust_4=0
replace _trust_4=0.5 if qa13_4==3
replace _trust_4=1 if qa13_4==2
gen _trust_5=0
replace _trust_5=0.5 if qa13_5==3
replace _trust_5=1 if qa13_5==2
gen _trust=(_trust_1+_trust_2+_trust_3+_trust_4+_trust_5)/5
replace _trust=. if studyno1==7561

gen D_Performance_std=(_trust-.3940524)/.3806758
gen D_Performance_std_w=(_trust-.4696867)/.3911237


******** INSTRUMENTAL ********
gen _member=.
replace _member=0 if qa11==1
replace _member=.5 if qa11==3 | qa11==4 | qa11==5
replace _member=1 if qa11==2

gen _benefit=.
replace _benefit=0 if qa12==1
replace _benefit=.5 if qa12==3 | qa12==4
replace _benefit=1 if qa12==2

gen D_Instrumental_std=(_benefit-.2221467)/.3965655

gen D_Instrumental_std_w=(_benefit-.2709282)/.4239277

******** POLITICAL ********
gen _decisions=.
replace _decisions=0 if qa17a_6==1
replace _decisions=.25 if qa17a_6==2
replace _decisions=.5 if qa17a_6==5
replace _decisions=.75 if qa17a_6==3
replace _decisions=1 if qa17a_6==4


gen D_Political_std=(_decisions-.4485569)/.321546

gen D_Political_std_w=(_decisions-.4245131)/.318858


*Unweighted
twoway	(qfitci D_Performance_std I_right, lcolor("gs12"))						(qfitci D_Instrumental_std I_right, lcolor("gs12"))							(qfitci D_Identity_std I_right, lcolor("gs12"))						(qfitci D_Political_std I_right, lcolor("gs12")) ///
		(qfit D_Performance_std I_right, lcolor("black") lpattern("longdash"))	(qfit D_Instrumental_std I_right, lcolor("black") lpattern("shortdash"))	(qfit D_Identity_std I_right, lcolor("black") lpattern("solid"))	(qfit D_Political_std I_right, lcolor("black") lpattern("dash_dot")), legend(off) xlabel(1(1)10)
   
*Weighted
twoway	(qfitci D_Performance_std_w I_right [aweight=w23], lcolor("gs12"))						(qfitci D_Instrumental_std_w I_right [aweight=w23], lcolor("gs12"))							(qfitci D_Identity_std_w I_right [aweight=w23], lcolor("gs12"))						(qfitci D_Political_std_w I_right [aweight=w23], lcolor("gs12")) ///
		(qfit D_Performance_std_w I_right [aweight=w23], lcolor("black") lpattern("longdash"))	(qfit D_Instrumental_std_w I_right [aweight=w23], lcolor("black") lpattern("shortdash"))	(qfit D_Identity_std_w I_right [aweight=w23], lcolor("black") lpattern("solid"))	(qfit D_Political_std_w I_right [aweight=w23], lcolor("black") lpattern("dash_dot")), legend(off) xlabel(1(1)10)


*Label
twoway	(qfit D_Performance_std I_right, lcolor("black") lpattern("longdash")) ///
		(qfit D_Instrumental_std I_right, lcolor("black") lpattern("shortdash")) ///
		(qfit D_Identity_std I_right, lcolor("black") lpattern("solid")) ///
		(qfit D_Political_std I_right, lcolor("black") lpattern("dash_dot")), legend(lab(1 "Performance") lab(2 "Instrumental") lab(3 "Identity") lab(4 "Political"))


		
		
		
************** Cluster analysis **************
	***Generating dataset of aggregated values
tab country_sort [aweight=w23], sum(D_Performance_std_w)
tab country_sort [aweight=w23], sum(D_Instrumental_std_w)
tab country_sort [aweight=w23], sum(D_Identity_std_w)
tab country_sort [aweight=w23], sum(D_Political_std_w)
sort country_sort
by country_sort: pwcorr D_Performance_std_w I_right, sig
by country_sort: pwcorr D_Instrumental_std_w I_right, sig
by country_sort: pwcorr D_Identity_std_w I_right, sig
by country_sort: pwcorr D_Political_std_w I_right, sig



*******************************************************************************
*******************************************************************************
*******************************************************************************

gen cluster_dimensions=.
replace cluster_dimensions=1 if country_sort==1 | country_sort==3 | country_sort==4 | country_sort==19 | country_sort==21
replace cluster_dimensions=2 if country_sort==6 | country_sort==14 | country_sort==15 | country_sort==17 | country_sort==27
replace cluster_dimensions=3 if country_sort==2 | country_sort==5 | country_sort==11 | country_sort==8
replace cluster_dimensions=4 if country_sort==7 | country_sort==13 | country_sort==20 | country_sort==22 | country_sort==24 | country_sort==26
replace cluster_dimensions=5 if country_sort==10 | country_sort==16 | country_sort==23 | country_sort==25 | country_sort==28
replace cluster_dimensions=6 if country_sort==9 | country_sort==12 | country_sort==18

drop D_index
gen D_index=(D_Instrumental_std_imputed2+D_Identity_std+D_Performance_std+D_Political_std)/4
mi set wide
mi register imputed D_index
mi impute reg D_index = D_Instrumental_std_imputed2 D_Identity_std D_Performance_std D_Political_std, add(20) rseed(12345) replace


gen LR_3=.
replace LR_3=1 if I_right<=3
replace LR_3=2 if I_right>=4 & I_right<=7
replace LR_3=3 if I_right>=8
label define LR_3 1"Left" 2"Center" 3"Right"
label values LR_3 LR_3



******Identified clusters of member states
**Austria, United Kingdom, Italy, Greece & Czech Republic
twoway (qfitci D_Performance_std I_right, lcolor("gs12")) (qfitci D_Instrumental_std I_right, lcolor("gs12")) (qfitci D_Identity_std I_right, lcolor("gs12")) (qfitci D_Political_std I_right, lcolor("gs12")) /// 
(qfit D_Performance_std I_right, lcolor("black") lpattern("longdash")) (qfit D_Instrumental_std I_right, lcolor("black") lpattern("shortdash")) (qfit D_Identity_std I_right, lcolor("black") lpattern("solid")) (qfit D_Political_std I_right, lcolor("black") lpattern("dash_dot")) if country_sort==1  | country_sort==3  | country_sort==4  | country_sort==21  | country_sort==19, legend(off) xlabel(1(1)10) by(country_sort) yline(0) legend(cols(4) order(9 "Performance"  10 "Instrumental" 11 "Identity" 12 "Political"))
*significance plot
ciplot D_Performance_std D_Political_std D_Identity_std D_Instrumental_std_imputed2 if country_sort==1  | country_sort==3  | country_sort==4  | country_sort==21  | country_sort==19, by(country_sort)
mean D_index if LR_3== 1 & cluster_dimensions==1, over(country_sort)
eststo Left_1
mean D_index if LR_3== 2 & cluster_dimensions==1, over(country_sort)
eststo Center_1
mean D_index if LR_3== 3 & cluster_dimensions==1, over(country_sort)
eststo Right_1
su D_index, mean
coefplot Left_1 Center_1 Right_1, xtitle() xline(`r(mean)')
**France, Croatia, Spain, Slovenia & Cyprus
twoway (qfitci D_Performance_std I_right, lcolor("gs12")) (qfitci D_Instrumental_std I_right, lcolor("gs12")) (qfitci D_Identity_std I_right, lcolor("gs12")) (qfitci D_Political_std I_right, lcolor("gs12")) /// 
(qfit D_Performance_std I_right, lcolor("black") lpattern("longdash")) (qfit D_Instrumental_std I_right, lcolor("black") lpattern("shortdash")) (qfit D_Identity_std I_right, lcolor("black") lpattern("solid")) (qfit D_Political_std I_right, lcolor("black") lpattern("dash_dot")) if country_sort==6 | country_sort==14 | country_sort==15 | country_sort==17 | country_sort==27, legend(off) xlabel(1(1)10) by(country_sort) yline(0) legend(cols(4) order(9 "Performance"  10 "Instrumental" 11 "Identity" 12 "Political"))
*significance plot
ciplot D_Performance_std D_Political_std D_Identity_std D_Instrumental_std_imputed2 if country_sort==6 | country_sort==14 | country_sort==15 | country_sort==17 | country_sort==27, by(country_sort)
mean D_index if LR_3== 1 & cluster_dimensions==2, over(country_sort)
eststo Left_2
mean D_index if LR_3== 2 & cluster_dimensions==2, over(country_sort)
eststo Center_2
mean D_index if LR_3== 3 & cluster_dimensions==2, over(country_sort)
eststo Right_2
su D_index, mean
coefplot Left_2 Center_2 Right_2, xtitle() xline(`r(mean)')
**Germany, Netherlands, Luxembourg & Belgium
twoway (qfitci D_Performance_std I_right, lcolor("gs12")) (qfitci D_Instrumental_std I_right, lcolor("gs12")) (qfitci D_Identity_std I_right, lcolor("gs12")) (qfitci D_Political_std I_right, lcolor("gs12")) /// 
(qfit D_Performance_std I_right, lcolor("black") lpattern("longdash")) (qfit D_Instrumental_std I_right, lcolor("black") lpattern("shortdash")) (qfit D_Identity_std I_right, lcolor("black") lpattern("solid")) (qfit D_Political_std I_right, lcolor("black") lpattern("dash_dot")) if country_sort==2 | country_sort==5 | country_sort==8 | country_sort==11, legend(off) xlabel(1(1)10) by(country_sort)  yline(0) legend(cols(4) order(9 "Performance"  10 "Instrumental" 11 "Identity" 12 "Political"))
ciplot D_Performance_std D_Political_std D_Identity_std D_Instrumental_std_imputed2 if country_sort==2 | country_sort==5 | country_sort==8 | country_sort==11, by(country_sort)
*significance plot
ciplot D_Performance_std D_Political_std D_Identity_std D_Instrumental_std_imputed2 if country_sort==2 | country_sort==5 | country_sort==8 | country_sort==11, by(country_sort)
mean D_index if LR_3== 1 & cluster_dimensions==3, over(country_sort)
eststo Left_3
mean D_index if LR_3== 2 & cluster_dimensions==3, over(country_sort)
eststo Center_3
mean D_index if LR_3== 3 & cluster_dimensions==3, over(country_sort)
eststo Right_3
su D_index, mean
coefplot Left_3 Center_3 Right_3, xtitle() xline(`r(mean)')
**Poland, Portugal, Ireland, Lithuania, Estonia & Malta
twoway (qfitci D_Performance_std I_right, lcolor("gs12")) (qfitci D_Instrumental_std I_right, lcolor("gs12")) (qfitci D_Identity_std I_right, lcolor("gs12")) (qfitci D_Political_std I_right, lcolor("gs12")) /// 
(qfit D_Performance_std I_right, lcolor("black") lpattern("longdash")) (qfit D_Instrumental_std I_right, lcolor("black") lpattern("shortdash")) (qfit D_Identity_std I_right, lcolor("black") lpattern("solid")) (qfit D_Political_std I_right, lcolor("black") lpattern("dash_dot")) if country_sort==7 | country_sort==13 | country_sort==20 | country_sort==22 | country_sort==24 | country_sort==26, legend(off) xlabel(1(1)10) by(country_sort)  yline(0) legend(cols(4) order(9 "Performance"  10 "Instrumental" 11 "Identity" 12 "Political"))
*significance plot
ciplot D_Performance_std D_Political_std D_Identity_std D_Instrumental_std_imputed2 if country_sort==7 | country_sort==13 | country_sort==20 | country_sort==22 | country_sort==24 | country_sort==26, by(country_sort)
mean D_index if LR_3== 1 & cluster_dimensions==4, over(country_sort)
eststo Left_4
mean D_index if LR_3== 2 & cluster_dimensions==4, over(country_sort)
eststo Center_4
mean D_index if LR_3== 3 & cluster_dimensions==4, over(country_sort)
eststo Right_4
su D_index, mean
coefplot Left_4 Center_4 Right_4, xtitle() xline(`r(mean)')
**Hungary, Romania, Latvia, Slovakia, Bulgaria
twoway (qfitci D_Performance_std I_right, lcolor("gs12")) (qfitci D_Instrumental_std I_right, lcolor("gs12")) (qfitci D_Identity_std I_right, lcolor("gs12")) (qfitci D_Political_std I_right, lcolor("gs12")) /// 
(qfit D_Performance_std I_right, lcolor("black") lpattern("longdash")) (qfit D_Instrumental_std I_right, lcolor("black") lpattern("shortdash")) (qfit D_Identity_std I_right, lcolor("black") lpattern("solid")) (qfit D_Political_std I_right, lcolor("black") lpattern("dash_dot")) if country_sort==10 | country_sort==23 | country_sort==25 | country_sort==16 | country_sort==28, legend(off) xlabel(1(1)10) by(country_sort)  yline(0) legend(cols(4) order(9 "Performance"  10 "Instrumental" 11 "Identity" 12 "Political"))
*significance plot
ciplot D_Performance_std D_Political_std D_Identity_std D_Instrumental_std_imputed2 if country_sort==10 | country_sort==23 | country_sort==25 | country_sort==16 | country_sort==28, by(country_sort)
mean D_index if LR_3== 1 & cluster_dimensions==5, over(country_sort)
eststo Left_5
mean D_index if LR_3== 2 & cluster_dimensions==5, over(country_sort)
eststo Center_5
mean D_index if LR_3== 3 & cluster_dimensions==5, over(country_sort)
eststo Right_5
su D_index, mean
coefplot Left_5 Center_5 Right_5, xtitle() xline(`r(mean)')
**Denmark, Sweden & Finland
twoway (qfitci D_Performance_std I_right, lcolor("gs12")) (qfitci D_Instrumental_std I_right, lcolor("gs12")) (qfitci D_Identity_std I_right, lcolor("gs12")) (qfitci D_Political_std I_right, lcolor("gs12")) /// 
(qfit D_Performance_std I_right, lcolor("black") lpattern("longdash")) (qfit D_Instrumental_std I_right, lcolor("black") lpattern("shortdash")) (qfit D_Identity_std I_right, lcolor("black") lpattern("solid")) (qfit D_Political_std I_right, lcolor("black") lpattern("dash_dot")) if country_sort==9 | country_sort==12 | country_sort==18, legend(off) xlabel(1(1)10) by(country_sort)  yline(0) legend(cols(4) order(9 "Performance"  10 "Instrumental" 11 "Identity" 12 "Political"))
*significance plot
ciplot D_Performance_std D_Political_std D_Identity_std D_Instrumental_std_imputed2 if country_sort==9 | country_sort==12 | country_sort==18, by(country_sort)
mean D_index if LR_3== 1 & cluster_dimensions==6, over(country_sort)
eststo Left_6
mean D_index if LR_3== 2 & cluster_dimensions==6, over(country_sort)
eststo Center_6
mean D_index if LR_3== 3 & cluster_dimensions==6, over(country_sort)
eststo Right_6
su D_index, mean
coefplot Left_6 Center_6 Right_6, xtitle() xline(`r(mean)')


****** ttests of mean difference from zero
bysort cluster_dimensions: ttest D_Performance_std==0
bysort cluster_dimensions: ttest D_Instrumental_std==0
bysort cluster_dimensions: ttest D_Identity_std==0
bysort cluster_dimensions: ttest D_Political_std==0






***Generating dataset of aggregated values
tab country_sort [aweight=w23], sum(DEP_utilitarianism_std_w)
tab country_sort [aweight=w23], sum(DEP_strengthening_std_w)
tab country_sort [aweight=w23], sum(DEP_Identity_std_w)
sort country_sort
by country_sort: pwcorr DEP_utilitarianism_std_w I_right, sig
by country_sort: pwcorr DEP_strengthening_std_w I_right, sig
by country_sort: pwcorr DEP_Identity_std_w I_right, sig


